package com.quo.controller;

import java.time.LocalDateTime;

import javax.mail.internet.MimeMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("emailTimeController")
public class EmailTimeController {
	@Autowired
	private JavaMailSender javaMailsender;
	@Value("${spring.mail.username}")
	private String from;
	//添加定时任务
    @Scheduled(cron = "0 0 12 * * ?")
    public void contextLoads() {
		SimpleMailMessage message = new SimpleMailMessage();
		message.setTo("litiangang0422@proton.me");
		message.setSubject("邮件主题：简单邮件");
		message.setText("邮件内容：测试简单邮件");
		message.setFrom(from);
		javaMailsender.send(message);

        System.out.println("执行定时任务 " + LocalDateTime.now());
	}
}
